package com.yzk.train.business.config;

import com.yzk.train.common.interceptor.LogInterceptor;
import com.yzk.train.common.interceptor.MemberInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {

    @Resource
    LogInterceptor logInterceptor;

    @Resource
    MemberInterceptor memberInterceptor;

    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 日志拦截器，获取流水号
        registry.addInterceptor(logInterceptor);
        // 会员拦截器，设置会员信息到上下文
        registry.addInterceptor(memberInterceptor)
                .addPathPatterns("/**");
    }
}
